package com.shop.myweb.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

public class SMSUtils {
    public static void sendMessage(String phoneNumbers, String param) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tADvU1RaKCWrndUX6im", "UmsThhSHxisEs8Tyt3IEkHXiJJlfBS");

        IAcsClient client = new DefaultAcsClient(profile);


        SendSmsRequest request = new SendSmsRequest();
        request.setSignName("瑞吉外卖点餐平台");
        request.setTemplateCode("SMS_276485603");
        request.setPhoneNumbers(phoneNumbers);
        request.setTemplateParam("{\"code\":\"" + param + "\"}");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }

}
